

import {downloadFile,filedownload,UploadFile} from "@/api/system";
const textfile = {
  data() {
    return {
      fileListtextMixin:[],
      filenametemptext:'',
    }
  },
  methods:{
    // 规划文本附件上传
    submitUploadtextMixin(param) {
      const formData = new FormData()
      formData.append(param.file.uid, param.file)
      UploadFile(formData,{fileType:'3'},param).then(response => {
        if (response.data.code == 0) {
          this.projectForm.textId = response.data.data;
          this.fileListtextMixin = [{name: param.file.name, url:response.data.data}]
          this.filenametemptext = param.file.name;
          this.$notify({
            title: "成功",
            message: "上传成功",
            type: "success",
            duration: 2000
          });
        }
      }).catch(response => {
        this.fileListtextMixin=[];
        this.$notify({
          title: "失败",
          message: "上传失败",
          type: "error",
          duration: 2000
        });

      })
    },
    fileChangetextMixin(file){
      // this.$refs.upload.clearFiles() //清除文件对象
    },

    handleRemovetextMixin(file, fileList){
      this.projectForm.textId = null;
    },
    handlePreviewtextMixin(file) {
      filedownload(this.projectForm.textId).then(response => {
        if(response.status==200){
          this.downloadMixin(response.data,this.filenametemptext)
        }
      }).catch((error) => {

      })
    },
    // 下载文件
    downloadMixin (data,filename) {
      if (data==null) {
        return
      }else{
        let url = window.URL.createObjectURL(new Blob([data]))
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download',filename )
        document.body.appendChild(link)
        link.click()
      }
    },
  }


};

export default textfile;
